<template>
  <div>登录{{ is_admin }}
    <button @click="tologin">admin登录</button>
    <button @click="toviplogin">vip登录</button>
  </div>
</template>

<script setup>
import { ref, reactive, toRefs, onBeforeMount, onMounted, watchEffect, computed } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { ApiLogin, ApiLoginLocal, ApiVipLogin } from '@/api/menulist'
import { userMenuListStore } from '@/store/index'
import axios from 'axios';
const store = userMenuListStore()
const { is_admin, token } = toRefs(store)
const router = useRouter();
/**
* 数据部分
*/
const data = reactive({})
// 调用部分\
const tologin = async () => {
  const data = await ApiLogin()
  // const { data } = await axios.get("api/login?user=admin");
  console.log(data, '登录')
  localStorage.setItem('token', data.data.token)
  localStorage.setItem('is_admin', data.data.is_admin)
  store.is_admin = data.data.is_admin
  store.token = data.data.token
  router.push('/dashboard')
}
const toviplogin = async () => {
  const data = await ApiVipLogin()
  // const { data } = await axios.get("api/login?user=vip");
  console.log(data, '登录')
  localStorage.setItem('token', data.data.token)
  localStorage.setItem('is_admin', data.data.is_admin)
  store.is_admin = data.data.is_admin
  store.token = data.data.token
  router.push('/dashboard')
}
onBeforeMount(() => {
  //console.log('2.组件挂载页面之前执行----onBeforeMount')
})
onMounted(() => {
  //console.log('3.-组件挂载到页面之后执行-------onMounted')
})
watchEffect(() => {
})
// 使用toRefs解构
// let { } = { ...toRefs(data) }
defineExpose({
  ...toRefs(data)
})

</script>
<style scoped lang='scss'></style>